<?php

namespace Database\Factories;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = User::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'account' => $this->faker->numberBetween(100000, 500000),
            'password' => bcrypt(12345), //使用Hash生成随机的密码
            'nickname' => Str::random(5), //随机生成用户名称
            'real_name' => Str::random(5),
            'avatar' => 'https://placeimg.com/640/480/any',
            'birthday' => $this->faker->dateTimeBetween('2019-01-01', 'now', 'PRC'),
            'email' => $this->faker->unique()->safeEmail, //生成随机的唯一的邮箱
            'balance' => $this->faker->numberBetween(100, 20000),
            'level' => $this->faker->numberBetween(1, 100),
            'remark' => $this->faker->text(),
            'system_admin_id' => 1,
            'country' => $this->faker->numberBetween(0, 1),
            'sex' => $this->faker->numberBetween(0, 1),
            'is_member' => $this->faker->numberBetween(0, 1),
            'group_id' => $this->faker->numberBetween(1, 10),
            'pay_count' => $this->faker->numberBetween(0, 30),
            'label_id' => $this->faker->numberBetween(1, 10),
            'phone' => $this->faker->phoneNumber,
            'user_type' => $this->faker->randomElement(['officialAccount', 'applet', 'h5', 'pc', 'app']),
            'last_time' => $this->faker->time('Y-m-d H:i:s'),
            'card_id' => '12345678912345678x',
            'promoter_id' => $this->faker->randomElement(User::pluck('id')),
            'addres' => '中国河北省',
        ];
    }

    /**
     * Indicate that the model's email address should be unverified.
     *
     * @return \Illuminate\Database\Eloquent\Factories\Factory
     */
    public function unverified()
    {
        return $this->state(function (array $attributes) {
            return [
                'email_verified_at' => null,
            ];
        });
    }
}
